# uncompyle6 version 3.2.3
# Python bytecode 3.6 (3379)
# Decompiled from: Python 3.6.8 |Anaconda custom (64-bit)| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]
# Embedded file name: site-packages\requests\adapters.py
"""
requests.adapters
~~~~~~~~~~~~~~~~~

This module contains the transport adapters that Requests uses to define
and maintain connections.
"""
import os.path, socket
from urllib3.poolmanager import PoolManager, proxy_from_url
from urllib3.response import HTTPResponse
from urllib3.util import Timeout as TimeoutSauce
from urllib3.util.retry import Retry
from urllib3.exceptions import ClosedPoolError
from urllib3.exceptions import ConnectTimeoutError
from urllib3.exceptions import HTTPError as _HTTPError
from urllib3.exceptions import MaxRetryError
from urllib3.exceptions import NewConnectionError
from urllib3.exceptions import ProxyError as _ProxyError
from urllib3.exceptions import ProtocolError
from urllib3.exceptions import ReadTimeoutError
from urllib3.exceptions import SSLError as _SSLError
from urllib3.exceptions import ResponseError
from .models import Response
from .compat import urlparse, basestring
from .utils import DEFAULT_CA_BUNDLE_PATH, get_encoding_from_headers, prepend_scheme_if_needed, get_auth_from_url, urldefragauth, select_proxy
from .structures import CaseInsensitiveDict
from .cookies import extract_cookies_to_jar
from .exceptions import ConnectionError, ConnectTimeout, ReadTimeout, SSLError, ProxyError, RetryError, InvalidSchema
from .auth import _basic_auth_str
try:
    from urllib3.contrib.socks import SOCKSProxyManager
except ImportError:

    def SOCKSProxyManager(*args, **kwargs):
        raise InvalidSchema('Missing dependencies for SOCKS support.')


DEFAULT_POOLBLOCK = False
DEFAULT_POOLSIZE = 10
DEFAULT_RETRIES = 0
DEFAULT_POOL_TIMEOUT = None

class BaseAdapter(object):
    """The Base Transport Adapter"""

    def __init__(self):
        super(BaseAdapter, self).__init__()

    def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None):
        """Sends PreparedRequest object. Returns Response object.
        
        :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
        :param stream: (optional) Whether to stream the request content.
        :param timeout: (optional) How long to wait for the server to send
            data before giving up, as a float, or a :ref:`(connect timeout,
            read timeout) <timeouts>` tuple.
        :type timeout: float or tuple
        :param verify: (optional) Either a boolean, in which case it controls whether we verify
            the server's TLS certificate, or a string, in which case it must be a path
            to a CA bundle to use
        :param cert: (optional) Any user-provided SSL certificate to be trusted.
        :param proxies: (optional) The proxies dictionary to apply to the request.
        """
        raise NotImplementedError

    def close(self):
        """Cleans up adapter specific items."""
        raise NotImplementedError


class HTTPAdapter(BaseAdapter):
    """The built-in HTTP Adapter for urllib3.
    
    Provides a general-case interface for Requests sessions to contact HTTP and
    HTTPS urls by implementing the Transport Adapter interface. This class will
    usually be created by the :class:`Session <Session>` class under the
    covers.
    
    :param pool_connections: The number of urllib3 connection pools to cache.
    :param pool_maxsize: The maximum number of connections to save in the pool.
    :param max_retries: The maximum number of retries each connection
        should attempt. Note, this applies only to failed DNS lookups, socket
        connections and connection timeouts, never to requests where data has
        made it to the server. By default, Requests does not retry failed
        connections. If you need granular control over the conditions under
        which we retry a request, import urllib3's ``Retry`` class and pass
        that instead.
    :param pool_block: Whether the connection pool should block for connections.
    
    Usage::
    
      >>> import requests
      >>> s = requests.Session()
      >>> a = requests.adapters.HTTPAdapter(max_retries=3)
      >>> s.mount('http://', a)
    """
    __attrs__ = [
     'max_retries', 'config', '_pool_connections', '_pool_maxsize',
     '_pool_block']

    def __init__(self, pool_connections=DEFAULT_POOLSIZE, pool_maxsize=DEFAULT_POOLSIZE, max_retries=DEFAULT_RETRIES, pool_block=DEFAULT_POOLBLOCK):
        if max_retries == DEFAULT_RETRIES:
            self.max_retries = Retry(0, read=False)
        else:
            self.max_retries = Retry.from_int(max_retries)
        self.config = {}
        self.proxy_manager = {}
        super(HTTPAdapter, self).__init__()
        self._pool_connections = pool_connections
        self._pool_maxsize = pool_maxsize
        self._pool_block = pool_block
        self.init_poolmanager(pool_connections, pool_maxsize, block=pool_block)

    def __getstate__(self):
        return dict(((attr, getattr(self, attr, None)) for attr in self.__attrs__))

    def __setstate__(self, state):
        self.proxy_manager = {}
        self.config = {}
        for attr, value in state.items():
            setattr(self, attr, value)

        self.init_poolmanager(self._pool_connections, self._pool_maxsize, block=self._pool_block)

    def init_poolmanager(self, connections, maxsize, block=DEFAULT_POOLBLOCK, **pool_kwargs):
        """Initializes a urllib3 PoolManager.
        
        This method should not be called from user code, and is only
        exposed for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
        
        :param connections: The number of urllib3 connection pools to cache.
        :param maxsize: The maximum number of connections to save in the pool.
        :param block: Block when no free connections are available.
        :param pool_kwargs: Extra keyword arguments used to initialize the Pool Manager.
        """
        self._pool_connections = connections
        self._pool_maxsize = maxsize
        self._pool_block = block
        self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize, block=block, 
         strict=True, **pool_kwargs)

    def proxy_manager_for(self, proxy, **proxy_kwargs):
        """Return urllib3 ProxyManager for the given proxy.
        
        This method should not be called from user code, and is only
        exposed for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
        
        :param proxy: The proxy to return a urllib3 ProxyManager for.
        :param proxy_kwargs: Extra keyword arguments used to configure the Proxy Manager.
        :returns: ProxyManager
        :rtype: urllib3.ProxyManager
        """
        if proxy in self.proxy_manager:
            manager = self.proxy_manager[proxy]
        else:
            if proxy.lower().startswith('socks'):
                username, password = get_auth_from_url(proxy)
                manager = self.proxy_manager[proxy] = SOCKSProxyManager(username=username, 
                 password=password, 
                 num_pools=self._pool_connections, 
                 maxsize=self._pool_maxsize, 
                 block=self._pool_block, **proxy_kwargs)
            else:
                proxy_headers = self.proxy_headers(proxy)
                manager = self.proxy_manager[proxy] = proxy_from_url(proxy_headers=proxy_headers, 
                 num_pools=self._pool_connections, 
                 maxsize=self._pool_maxsize, 
                 block=self._pool_block, **proxy_kwargs)
            return manager

    def cert_verify(self, conn, url, verify, cert):
        """Verify a SSL certificate. This method should not be called from user
        code, and is only exposed for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
        
        :param conn: The urllib3 connection object associated with the cert.
        :param url: The requested URL.
        :param verify: Either a boolean, in which case it controls whether we verify
            the server's TLS certificate, or a string, in which case it must be a path
            to a CA bundle to use
        :param cert: The SSL certificate to verify.
        """
        if url.lower().startswith('https'):
            if verify:
                cert_loc = None
                if verify is not True:
                    cert_loc = verify
                if not cert_loc:
                    cert_loc = DEFAULT_CA_BUNDLE_PATH
                if not cert_loc or not os.path.exists(cert_loc):
                    raise IOError(('Could not find a suitable TLS CA certificate bundle, invalid path: {0}').format(cert_loc))
                conn.cert_reqs = 'CERT_REQUIRED'
                if not os.path.isdir(cert_loc):
                    conn.ca_certs = cert_loc
                else:
                    conn.ca_cert_dir = cert_loc
            conn.cert_reqs = 'CERT_NONE'
            conn.ca_certs = None
            conn.ca_cert_dir = None
        if cert:
            if not isinstance(cert, basestring):
                conn.cert_file = cert[0]
                conn.key_file = cert[1]
            else:
                conn.cert_file = cert
                conn.key_file = None
            if conn.cert_file:
                if not os.path.exists(conn.cert_file):
                    raise IOError(('Could not find the TLS certificate file, invalid path: {0}').format(conn.cert_file))
            if conn.key_file and not os.path.exists(conn.key_file):
                raise IOError(('Could not find the TLS key file, invalid path: {0}').format(conn.key_file))

    def build_response(self, req, resp):
        """Builds a :class:`Response <requests.Response>` object from a urllib3
        response. This should not be called from user code, and is only exposed
        for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`
        
        :param req: The :class:`PreparedRequest <PreparedRequest>` used to generate the response.
        :param resp: The urllib3 response object.
        :rtype: requests.Response
        """
        response = Response()
        response.status_code = getattr(resp, 'status', None)
        response.headers = CaseInsensitiveDict(getattr(resp, 'headers', {}))
        response.encoding = get_encoding_from_headers(response.headers)
        response.raw = resp
        response.reason = response.raw.reason
        if isinstance(req.url, bytes):
            response.url = req.url.decode('utf-8')
        else:
            response.url = req.url
        extract_cookies_to_jar(response.cookies, req, resp)
        response.request = req
        response.connection = self
        return response

    def get_connection(self, url, proxies=None):
        """Returns a urllib3 connection for the given URL. This should not be
        called from user code, and is only exposed for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
        
        :param url: The URL to connect to.
        :param proxies: (optional) A Requests-style dictionary of proxies used on this request.
        :rtype: urllib3.ConnectionPool
        """
        proxy = select_proxy(url, proxies)
        if proxy:
            proxy = prepend_scheme_if_needed(proxy, 'http')
            proxy_manager = self.proxy_manager_for(proxy)
            conn = proxy_manager.connection_from_url(url)
        else:
            parsed = urlparse(url)
            url = parsed.geturl()
            conn = self.poolmanager.connection_from_url(url)
        return conn

    def close(self):
        """Disposes of any internal state.
        
        Currently, this closes the PoolManager and any active ProxyManager,
        which closes any pooled connections.
        """
        self.poolmanager.clear()
        for proxy in self.proxy_manager.values():
            proxy.clear()

    def request_url(self, request, proxies):
        """Obtain the url to use when making the final request.
        
        If the message is being sent through a HTTP proxy, the full URL has to
        be used. Otherwise, we should only use the path portion of the URL.
        
        This should not be called from user code, and is only exposed for use
        when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
        
        :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
        :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs.
        :rtype: str
        """
        proxy = select_proxy(request.url, proxies)
        scheme = urlparse(request.url).scheme
        is_proxied_http_request = proxy and scheme != 'https'
        using_socks_proxy = False
        if proxy:
            proxy_scheme = urlparse(proxy).scheme.lower()
            using_socks_proxy = proxy_scheme.startswith('socks')
        url = request.path_url
        if is_proxied_http_request:
            if not using_socks_proxy:
                url = urldefragauth(request.url)
        return url

    def add_headers(self, request, **kwargs):
        """Add any headers needed by the connection. As of v2.0 this does
        nothing by default, but is left for overriding by users that subclass
        the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
        
        This should not be called from user code, and is only exposed for use
        when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
        
        :param request: The :class:`PreparedRequest <PreparedRequest>` to add headers to.
        :param kwargs: The keyword arguments from the call to send().
        """
        pass

    def proxy_headers(self, proxy):
        """Returns a dictionary of the headers to add to any request sent
        through a proxy. This works with urllib3 magic to ensure that they are
        correctly sent to the proxy, rather than in a tunnelled request if
        CONNECT is being used.
        
        This should not be called from user code, and is only exposed for use
        when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
        
        :param proxies: The url of the proxy being used for this request.
        :rtype: dict
        """
        headers = {}
        username, password = get_auth_from_url(proxy)
        if username:
            headers['Proxy-Authorization'] = _basic_auth_str(username, password)
        return headers

    def send--- This code section failed: ---

 405       0  LOAD_FAST                'self'
           2  LOAD_ATTR                'get_connection'
           4  LOAD_FAST                'request'
           6  LOAD_ATTR                'url'
           8  LOAD_FAST                'proxies'
          10  CALL_FUNCTION_2       2  ''
          12  STORE_FAST               'conn'

 407      14  LOAD_FAST                'self'
          16  LOAD_ATTR                'cert_verify'
          18  LOAD_FAST                'conn'
          20  LOAD_FAST                'request'
          22  LOAD_ATTR                'url'
          24  LOAD_FAST                'verify'
          26  LOAD_FAST                'cert'
          28  CALL_FUNCTION_4       4  ''
          30  POP_TOP          

 408      32  LOAD_FAST                'self'
          34  LOAD_ATTR                'request_url'
          36  LOAD_FAST                'request'
          38  LOAD_FAST                'proxies'
          40  CALL_FUNCTION_2       2  ''
          42  STORE_FAST               'url'

 409      44  LOAD_FAST                'self'
          46  LOAD_ATTR                'add_headers'
          48  LOAD_FAST                'request'
          50  CALL_FUNCTION_1       1  ''
          52  POP_TOP          

 411      54  LOAD_FAST                'request'
          56  LOAD_ATTR                'body'
          58  LOAD_CONST               None
          60  COMPARE_OP               'is'
          62  JUMP_IF_TRUE_OR_POP    72  'to 72'
          64  LOAD_CONST               'Content-Length'
          66  LOAD_FAST                'request'
          68  LOAD_ATTR                'headers'
          70  COMPARE_OP               'in'
        72_0  COME_FROM            62  '62'
          72  UNARY_NOT        
          74  STORE_FAST               'chunked'

 413      76  LOAD_GLOBAL              'isinstance'
          78  LOAD_FAST                'timeout'
          80  LOAD_GLOBAL              'tuple'
          82  CALL_FUNCTION_2       2  ''
          84  POP_JUMP_IF_FALSE   166  'to 166'

 414      86  SETUP_EXCEPT        112  'to 112'

 415      88  LOAD_FAST                'timeout'
          90  UNPACK_SEQUENCE_2     2  ''
          92  STORE_FAST               'connect'
          94  STORE_FAST               'read'

 416      96  LOAD_GLOBAL              'TimeoutSauce'
          98  LOAD_FAST                'connect'
         100  LOAD_FAST                'read'
         102  LOAD_CONST               ('connect', 'read')
         104  CALL_FUNCTION_KW_2     2  ''
         106  STORE_FAST               'timeout'
         108  POP_BLOCK        
         110  JUMP_ABSOLUTE       190  'to 190'
       112_0  COME_FROM_EXCEPT     86  '86'

 417     112  DUP_TOP          
         114  LOAD_GLOBAL              'ValueError'
         116  COMPARE_OP               'exception-match'
         118  POP_JUMP_IF_FALSE   162  'to 162'
         120  POP_TOP          
         122  STORE_FAST               'e'
         124  POP_TOP          
         126  SETUP_FINALLY       152  'to 152'

 419     128  LOAD_CONST               'Invalid timeout {0}. Pass a (connect, read) timeout tuple, or a single float to set both timeouts to the same value'
         130  LOAD_ATTR                'format'

 421     132  LOAD_FAST                'timeout'
         134  CALL_FUNCTION_1       1  ''
         136  STORE_FAST               'err'

 422     138  LOAD_GLOBAL              'ValueError'
         140  LOAD_FAST                'err'
         142  CALL_FUNCTION_1       1  ''
         144  RAISE_VARARGS_1       1  ''
         146  POP_BLOCK        
         148  POP_EXCEPT       
         150  LOAD_CONST               None
       152_0  COME_FROM_FINALLY   126  '126'
         152  LOAD_CONST               None
         154  STORE_FAST               'e'
         156  DELETE_FAST              'e'
         158  END_FINALLY      
         160  JUMP_ABSOLUTE       190  'to 190'
         162  END_FINALLY      
         164  JUMP_FORWARD        190  'to 190'

 423     166  LOAD_GLOBAL              'isinstance'
         168  LOAD_FAST                'timeout'
         170  LOAD_GLOBAL              'TimeoutSauce'
         172  CALL_FUNCTION_2       2  ''
         174  POP_JUMP_IF_FALSE   178  'to 178'

 424     176  JUMP_FORWARD        190  'to 190'
         178  ELSE                     '190'

 426     178  LOAD_GLOBAL              'TimeoutSauce'
         180  LOAD_FAST                'timeout'
         182  LOAD_FAST                'timeout'
         184  LOAD_CONST               ('connect', 'read')
         186  CALL_FUNCTION_KW_2     2  ''
         188  STORE_FAST               'timeout'
       190_0  COME_FROM           176  '176'
       190_1  COME_FROM           164  '164'

 428     190  SETUP_EXCEPT        526  'to 526'

 429     194  LOAD_FAST                'chunked'
         196  POP_JUMP_IF_TRUE    240  'to 240'

 430     198  LOAD_FAST                'conn'
         200  LOAD_ATTR                'urlopen'

 431     202  LOAD_FAST                'request'
         204  LOAD_ATTR                'method'

 432     206  LOAD_FAST                'url'

 433     208  LOAD_FAST                'request'
         210  LOAD_ATTR                'body'

 434     212  LOAD_FAST                'request'
         214  LOAD_ATTR                'headers'

 435     216  LOAD_CONST            0  False

 436     218  LOAD_CONST            0  False

 437     220  LOAD_CONST            0  False

 438     222  LOAD_CONST            0  False

 439     224  LOAD_FAST                'self'
         226  LOAD_ATTR                'max_retries'

 440     228  LOAD_FAST                'timeout'
         230  LOAD_CONST               ('method', 'url', 'body', 'headers', 'redirect', 'assert_same_host', 'preload_content', 'decode_content', 'retries', 'timeout')
         232  CALL_FUNCTION_KW_10    10  ''
         234  STORE_FAST               'resp'
         236  JUMP_FORWARD        520  'to 520'
         240  ELSE                     '520'

 445     240  LOAD_GLOBAL              'hasattr'
         242  LOAD_FAST                'conn'
         244  LOAD_CONST               'proxy_pool'
         246  CALL_FUNCTION_2       2  ''
         248  POP_JUMP_IF_FALSE   258  'to 258'

 446     252  LOAD_FAST                'conn'
         254  LOAD_ATTR                'proxy_pool'
         256  STORE_FAST               'conn'
       258_0  COME_FROM           248  '248'

 448     258  LOAD_FAST                'conn'
         260  LOAD_ATTR                '_get_conn'
         262  LOAD_GLOBAL              'DEFAULT_POOL_TIMEOUT'
         264  LOAD_CONST               ('timeout',)
         266  CALL_FUNCTION_KW_1     1  ''
         268  STORE_FAST               'low_conn'

 450     270  SETUP_EXCEPT        498  'to 498'

 451     272  LOAD_FAST                'low_conn'
         274  LOAD_ATTR                'putrequest'
         276  LOAD_FAST                'request'
         278  LOAD_ATTR                'method'

 452     280  LOAD_FAST                'url'

 453     282  LOAD_CONST            1  True
         284  LOAD_CONST               ('skip_accept_encoding',)
         286  CALL_FUNCTION_KW_3     3  ''
         288  POP_TOP          

 455     290  SETUP_LOOP          328  'to 328'
         292  LOAD_FAST                'request'
         294  LOAD_ATTR                'headers'
         296  LOAD_ATTR                'items'
         298  CALL_FUNCTION_0       0  ''
         300  GET_ITER         
         302  FOR_ITER            326  'to 326'
         304  UNPACK_SEQUENCE_2     2  ''
         306  STORE_FAST               'header'
         308  STORE_FAST               'value'

 456     310  LOAD_FAST                'low_conn'
         312  LOAD_ATTR                'putheader'
         314  LOAD_FAST                'header'
         316  LOAD_FAST                'value'
         318  CALL_FUNCTION_2       2  ''
         320  POP_TOP          
         322  JUMP_BACK           302  'to 302'
         326  POP_BLOCK        
       328_0  COME_FROM_LOOP      290  '290'

 458     328  LOAD_FAST                'low_conn'
         330  LOAD_ATTR                'endheaders'
         332  CALL_FUNCTION_0       0  ''
         334  POP_TOP          

 460     336  SETUP_LOOP          416  'to 416'
         338  LOAD_FAST                'request'
         340  LOAD_ATTR                'body'
         342  GET_ITER         
         344  FOR_ITER            414  'to 414'
         346  STORE_FAST               'i'

 461     348  LOAD_FAST                'low_conn'
         350  LOAD_ATTR                'send'
         352  LOAD_GLOBAL              'hex'
         354  LOAD_GLOBAL              'len'
         356  LOAD_FAST                'i'
         358  CALL_FUNCTION_1       1  ''
         360  CALL_FUNCTION_1       1  ''
         362  LOAD_CONST            2  2
         364  LOAD_CONST               None
         366  BUILD_SLICE_2         2  ''
         368  BINARY_SUBSCR    
         370  LOAD_ATTR                'encode'
         372  LOAD_CONST               'utf-8'
         374  CALL_FUNCTION_1       1  ''
         376  CALL_FUNCTION_1       1  ''
         378  POP_TOP          

 462     380  LOAD_FAST                'low_conn'
         382  LOAD_ATTR                'send'
         384  LOAD_CONST               b'\r\n'
         386  CALL_FUNCTION_1       1  ''
         388  POP_TOP          

 463     390  LOAD_FAST                'low_conn'
         392  LOAD_ATTR                'send'
         394  LOAD_FAST                'i'
         396  CALL_FUNCTION_1       1  ''
         398  POP_TOP          

 464     400  LOAD_FAST                'low_conn'
         402  LOAD_ATTR                'send'
         404  LOAD_CONST               b'\r\n'
         406  CALL_FUNCTION_1       1  ''
         408  POP_TOP          
         410  JUMP_BACK           344  'to 344'
         414  POP_BLOCK        
       416_0  COME_FROM_LOOP      336  '336'

 465     416  LOAD_FAST                'low_conn'
         418  LOAD_ATTR                'send'
         420  LOAD_CONST               b'0\r\n\r\n'
         422  CALL_FUNCTION_1       1  ''
         424  POP_TOP          

 468     426  SETUP_EXCEPT        444  'to 444'

 471     428  LOAD_FAST                'low_conn'
         430  LOAD_ATTR                'getresponse'
         432  LOAD_CONST            1  True
         434  LOAD_CONST               ('buffering',)
         436  CALL_FUNCTION_KW_1     1  ''
         438  STORE_FAST               'r'
         440  POP_BLOCK        
         442  JUMP_FORWARD        474  'to 474'
       444_0  COME_FROM_EXCEPT    426  '426'

 472     444  DUP_TOP          
         446  LOAD_GLOBAL              'TypeError'
         448  COMPARE_OP               'exception-match'
         450  POP_JUMP_IF_FALSE   472  'to 472'
         454  POP_TOP          
         456  POP_TOP          
         458  POP_TOP          

 474     460  LOAD_FAST                'low_conn'
         462  LOAD_ATTR                'getresponse'
         464  CALL_FUNCTION_0       0  ''
         466  STORE_FAST               'r'
         468  POP_EXCEPT       
         470  JUMP_FORWARD        474  'to 474'
         472  END_FINALLY      
       474_0  COME_FROM           470  '470'
       474_1  COME_FROM           442  '442'

 476     474  LOAD_GLOBAL              'HTTPResponse'
         476  LOAD_ATTR                'from_httplib'

 477     478  LOAD_FAST                'r'

 478     480  LOAD_FAST                'conn'

 479     482  LOAD_FAST                'low_conn'

 480     484  LOAD_CONST            0  False

 481     486  LOAD_CONST            0  False
         488  LOAD_CONST               ('pool', 'connection', 'preload_content', 'decode_content')
         490  CALL_FUNCTION_KW_5     5  ''
         492  STORE_FAST               'resp'
         494  POP_BLOCK        
         496  JUMP_FORWARD        520  'to 520'
       498_0  COME_FROM_EXCEPT    270  '270'

 483     498  POP_TOP          
         500  POP_TOP          
         502  POP_TOP          

 486     504  LOAD_FAST                'low_conn'
         506  LOAD_ATTR                'close'
         508  CALL_FUNCTION_0       0  ''
         510  POP_TOP          

 487     512  RAISE_VARARGS_0       0  ''
         514  POP_EXCEPT       
         516  JUMP_FORWARD        520  'to 520'
         518  END_FINALLY      
       520_0  COME_FROM           516  '516'
       520_1  COME_FROM           496  '496'
       520_2  COME_FROM           236  '236'
         520  POP_BLOCK        
         522  JUMP_FORWARD        926  'to 926'
       526_0  COME_FROM_EXCEPT    190  '190'

 489     526  DUP_TOP          
         528  LOAD_GLOBAL              'ProtocolError'
         530  LOAD_GLOBAL              'socket'
         532  LOAD_ATTR                'error'
         534  BUILD_TUPLE_2         2  ''
         536  COMPARE_OP               'exception-match'
         538  POP_JUMP_IF_FALSE   580  'to 580'
         542  POP_TOP          
         544  STORE_FAST               'err'
         546  POP_TOP          
         548  SETUP_FINALLY       568  'to 568'

 490     550  LOAD_GLOBAL              'ConnectionError'
         552  LOAD_FAST                'err'
         554  LOAD_FAST                'request'
         556  LOAD_CONST               ('request',)
         558  CALL_FUNCTION_KW_2     2  ''
         560  RAISE_VARARGS_1       1  ''
         562  POP_BLOCK        
         564  POP_EXCEPT       
         566  LOAD_CONST               None
       568_0  COME_FROM_FINALLY   548  '548'
         568  LOAD_CONST               None
         570  STORE_FAST               'err'
         572  DELETE_FAST              'err'
         574  END_FINALLY      
         576  JUMP_FORWARD        926  'to 926'
         580  ELSE                     '926'

 492     580  DUP_TOP          
         582  LOAD_GLOBAL              'MaxRetryError'
         584  COMPARE_OP               'exception-match'
         586  POP_JUMP_IF_FALSE   744  'to 744'
         590  POP_TOP          
         592  STORE_FAST               'e'
         594  POP_TOP          
         596  SETUP_FINALLY       734  'to 734'

 493     598  LOAD_GLOBAL              'isinstance'
         600  LOAD_FAST                'e'
         602  LOAD_ATTR                'reason'
         604  LOAD_GLOBAL              'ConnectTimeoutError'
         606  CALL_FUNCTION_2       2  ''
         608  POP_JUMP_IF_FALSE   638  'to 638'

 495     612  LOAD_GLOBAL              'isinstance'
         614  LOAD_FAST                'e'
         616  LOAD_ATTR                'reason'
         618  LOAD_GLOBAL              'NewConnectionError'
         620  CALL_FUNCTION_2       2  ''
         622  POP_JUMP_IF_TRUE    638  'to 638'

 496     626  LOAD_GLOBAL              'ConnectTimeout'
         628  LOAD_FAST                'e'
         630  LOAD_FAST                'request'
         632  LOAD_CONST               ('request',)
         634  CALL_FUNCTION_KW_2     2  ''
         636  RAISE_VARARGS_1       1  ''
       638_0  COME_FROM           622  '622'
       638_1  COME_FROM           608  '608'

 498     638  LOAD_GLOBAL              'isinstance'
         640  LOAD_FAST                'e'
         642  LOAD_ATTR                'reason'
         644  LOAD_GLOBAL              'ResponseError'
         646  CALL_FUNCTION_2       2  ''
         648  POP_JUMP_IF_FALSE   664  'to 664'

 499     652  LOAD_GLOBAL              'RetryError'
         654  LOAD_FAST                'e'
         656  LOAD_FAST                'request'
         658  LOAD_CONST               ('request',)
         660  CALL_FUNCTION_KW_2     2  ''
         662  RAISE_VARARGS_1       1  ''
       664_0  COME_FROM           648  '648'

 501     664  LOAD_GLOBAL              'isinstance'
         666  LOAD_FAST                'e'
         668  LOAD_ATTR                'reason'
         670  LOAD_GLOBAL              '_ProxyError'
         672  CALL_FUNCTION_2       2  ''
         674  POP_JUMP_IF_FALSE   690  'to 690'

 502     678  LOAD_GLOBAL              'ProxyError'
         680  LOAD_FAST                'e'
         682  LOAD_FAST                'request'
         684  LOAD_CONST               ('request',)
         686  CALL_FUNCTION_KW_2     2  ''
         688  RAISE_VARARGS_1       1  ''
       690_0  COME_FROM           674  '674'

 504     690  LOAD_GLOBAL              'isinstance'
         692  LOAD_FAST                'e'
         694  LOAD_ATTR                'reason'
         696  LOAD_GLOBAL              '_SSLError'
         698  CALL_FUNCTION_2       2  ''
         700  POP_JUMP_IF_FALSE   716  'to 716'

 506     704  LOAD_GLOBAL              'SSLError'
         706  LOAD_FAST                'e'
         708  LOAD_FAST                'request'
         710  LOAD_CONST               ('request',)
         712  CALL_FUNCTION_KW_2     2  ''
         714  RAISE_VARARGS_1       1  ''
       716_0  COME_FROM           700  '700'

 508     716  LOAD_GLOBAL              'ConnectionError'
         718  LOAD_FAST                'e'
         720  LOAD_FAST                'request'
         722  LOAD_CONST               ('request',)
         724  CALL_FUNCTION_KW_2     2  ''
         726  RAISE_VARARGS_1       1  ''
         728  POP_BLOCK        
         730  POP_EXCEPT       
         732  LOAD_CONST               None
       734_0  COME_FROM_FINALLY   596  '596'
         734  LOAD_CONST               None
         736  STORE_FAST               'e'
         738  DELETE_FAST              'e'
         740  END_FINALLY      
         742  JUMP_FORWARD        926  'to 926'

 510     744  DUP_TOP          
         746  LOAD_GLOBAL              'ClosedPoolError'
         748  COMPARE_OP               'exception-match'
         750  POP_JUMP_IF_FALSE   790  'to 790'
         754  POP_TOP          
         756  STORE_FAST               'e'
         758  POP_TOP          
         760  SETUP_FINALLY       780  'to 780'

 511     762  LOAD_GLOBAL              'ConnectionError'
         764  LOAD_FAST                'e'
         766  LOAD_FAST                'request'
         768  LOAD_CONST               ('request',)
         770  CALL_FUNCTION_KW_2     2  ''
         772  RAISE_VARARGS_1       1  ''
         774  POP_BLOCK        
         776  POP_EXCEPT       
         778  LOAD_CONST               None
       780_0  COME_FROM_FINALLY   760  '760'
         780  LOAD_CONST               None
         782  STORE_FAST               'e'
         784  DELETE_FAST              'e'
         786  END_FINALLY      
         788  JUMP_FORWARD        926  'to 926'

 513     790  DUP_TOP          
         792  LOAD_GLOBAL              '_ProxyError'
         794  COMPARE_OP               'exception-match'
         796  POP_JUMP_IF_FALSE   832  'to 832'
         800  POP_TOP          
         802  STORE_FAST               'e'
         804  POP_TOP          
         806  SETUP_FINALLY       822  'to 822'

 514     808  LOAD_GLOBAL              'ProxyError'
         810  LOAD_FAST                'e'
         812  CALL_FUNCTION_1       1  ''
         814  RAISE_VARARGS_1       1  ''
         816  POP_BLOCK        
         818  POP_EXCEPT       
         820  LOAD_CONST               None
       822_0  COME_FROM_FINALLY   806  '806'
         822  LOAD_CONST               None
         824  STORE_FAST               'e'
         826  DELETE_FAST              'e'
         828  END_FINALLY      
         830  JUMP_FORWARD        926  'to 926'

 516     832  DUP_TOP          
         834  LOAD_GLOBAL              '_SSLError'
         836  LOAD_GLOBAL              '_HTTPError'
         838  BUILD_TUPLE_2         2  ''
         840  COMPARE_OP               'exception-match'
         842  POP_JUMP_IF_FALSE   924  'to 924'
         846  POP_TOP          
         848  STORE_FAST               'e'
         850  POP_TOP          
         852  SETUP_FINALLY       914  'to 914'

 517     854  LOAD_GLOBAL              'isinstance'
         856  LOAD_FAST                'e'
         858  LOAD_GLOBAL              '_SSLError'
         860  CALL_FUNCTION_2       2  ''
         862  POP_JUMP_IF_FALSE   880  'to 880'

 519     866  LOAD_GLOBAL              'SSLError'
         868  LOAD_FAST                'e'
         870  LOAD_FAST                'request'
         872  LOAD_CONST               ('request',)
         874  CALL_FUNCTION_KW_2     2  ''
         876  RAISE_VARARGS_1       1  ''
         878  JUMP_FORWARD        908  'to 908'
         880  ELSE                     '908'

 520     880  LOAD_GLOBAL              'isinstance'
         882  LOAD_FAST                'e'
         884  LOAD_GLOBAL              'ReadTimeoutError'
         886  CALL_FUNCTION_2       2  ''
         888  POP_JUMP_IF_FALSE   906  'to 906'

 521     892  LOAD_GLOBAL              'ReadTimeout'
         894  LOAD_FAST                'e'
         896  LOAD_FAST                'request'
         898  LOAD_CONST               ('request',)
         900  CALL_FUNCTION_KW_2     2  ''
         902  RAISE_VARARGS_1       1  ''
         904  JUMP_FORWARD        908  'to 908'
         906  ELSE                     '908'

 523     906  RAISE_VARARGS_0       0  ''
       908_0  COME_FROM           904  '904'
       908_1  COME_FROM           878  '878'
         908  POP_BLOCK        
         910  POP_EXCEPT       
         912  LOAD_CONST               None
       914_0  COME_FROM_FINALLY   852  '852'
         914  LOAD_CONST               None
         916  STORE_FAST               'e'
         918  DELETE_FAST              'e'
         920  END_FINALLY      
         922  JUMP_FORWARD        926  'to 926'
         924  END_FINALLY      
       926_0  COME_FROM           922  '922'
       926_1  COME_FROM           830  '830'
       926_2  COME_FROM           788  '788'
       926_3  COME_FROM           742  '742'
       926_4  COME_FROM           576  '576'
       926_5  COME_FROM           522  '522'

 525     926  LOAD_FAST                'self'
         928  LOAD_ATTR                'build_response'
         930  LOAD_FAST                'request'
         932  LOAD_FAST                'resp'
         934  CALL_FUNCTION_2       2  ''
         936  RETURN_VALUE     
          -1  RETURN_LAST      

Parse error at or near `ELSE' instruction at offset 580